<style scoped lang="stylus" type="text/stylus">
.approval-Page {
  height: 100%;

  .edit-header {
    position: fixed;
    top: 0;
    height: 60px;
    line-height: 60px;
    padding-left: 40px;
    font-size: 18px;
    background-color: #4c4c4c;

    .route-title {
      color: #fff;
      cursor: pointer;
    }

    .page-name {
      color: #7f7f7f;
    }
  }

  .approval-Page-ps {
    position: relative;
    height: 100%;
    padding: 40px 0;

    .approval-items {
      width: 480px;
      margin: 0 auto;
      padding: 20px;
      margin-bottom: 20px;
      background-color: #e5e5e5;

      .name {
        margin-bottom: 20px;
        text-align: center;
        font-size: 18px;
      }

      .info {
        font-size: 14px;

        p {
          margin-bottom: 15px;

          &:last-child {
            margin-bottom: 0;
          }

          .mobile {
            margin-left: 30px;
          }
        }
      }

      .img {
        padding: 20px 0;

        .file {
          padding: 10px 0;

          a {
            font-size: 12px;
          }
        }
      }

      .footer {
        text-align: right;
      }
    }
  }

  .notContent {
    width: 100%;
    height: 100%;
    line-height: 100%;

    .icon-zanwuneirong {
      font-size: 150px;
      position: absolute;
      left: 50%;
      transform: translate(-50%);
      top: 40%;
    }

    .notContentName {
      position: absolute;
      left: 50%;
      transform: translate(-50%);
      top: 50%;
      font-size: 36px;
    }
  }
}
</style>

<template>
  <div class="approval-Page">
    <div class="notContent" v-show="approvalArr.length == 0">
      <i class="icon iconfont icon-zanwuneirong"></i>
      <div class="notContentName">暂无内容</div>
    </div>
    <div class="edit-header">
      <span @click="GoBack()" class="route-title">设置</span>
      <span class="page-name">&nbsp;/&nbsp;企业审核</span>
    </div>
    <VuePerfectScrollbar class="approval-Page-ps">
      <div class="approval-items" v-for="item in approvalArr" :key="item.id">
        <p class="name">{{item.name}}</p>
        <div class="info">
          <p class="number">企业统一社会信用代码：{{item.orgCode}}</p>
          <p class="number" v-if='item.chairman'>
            <span class="linkman">董事长姓名：{{item.chairman}}</span>
            <span class="mobile">联系方式：{{item.chairmanPhone}}</span>
          </p>
          <p class="number" v-if='item.generalManager'>
            <span class="linkman">总经理姓名：{{item.generalManager}}</span>
            <span class="mobile">联系方式：{{item.generalManagerPhone}}</span>
          </p>
          <p class="number" v-if='item.legalPersonName'>
            <span class="linkman">法人姓名：{{item.legalPersonName}}</span>
            <span class="mobile">联系方式： {{item.legalPersonPhone}}</span>
          </p>
        </div>
        <div class="img">
          <ul>
            <li class="file" v-for="(files,filesIndex) in item.files" :key="filesIndex">
              <a target="_blank" :href="files.filePath">{{files.fileName}}</a>
            </li>
          </ul>
        </div>
        <div class="footer">
          <Button type="error" @click="getCurrentCompanyId(item.id,'reject')">拒绝</Button>
          <Poptip
            transfer
            confirm
            title="是否确定同意该注册申请？"
            @on-ok="sub('approve')">
            <Button type="success" @click="getCurrentCompanyId(item.id,'approve')">批准</Button>
          </Poptip>
          <Modal
              v-model="modal1"
              title="填写拒绝理由"
              @on-ok="sub('reject')"
              @on-cancel="cancel">
              <Input v-model="value1" type="textarea" :autosize="true" placeholder="点击输入···"></Input>
          </Modal>
        </div>
      </div>
    </VuePerfectScrollbar>
  </div>
</template>

<script type="text/ecmascript-6">
export default {
  name: "Approval",
  data() {
    return {
      approvalArr: [],
      modal1: false,
      value1: "",
      currentCompanyId: ""
    };
  },
  computed: {},
  methods: {
    // 获取点击操作的企业id
    getCurrentCompanyId(id, action) {
      if (action == "reject") {
        this.modal1 = true;
        this.currentCompanyId = id;
      }
      if (action == "approve") {
        this.currentCompanyId = id;
      }
    },

    // 获取审核列表
    getList() {
      this.ajaxData(
        {
          type: "get",
          url: "/company/unaudit"
        },
        (res, all) => {
          if (all.code == 0) {
            this.approvalArr = res;
          }
        }
      );
    },
    urlFormat(str) {
      let s = "123,123";
      let arr = s.split(",");
      return arr;
    },
    downFile(url) {
      this.ajaxData(
        {
          type: "get",
          url: "/filecommon/downloadFile",
          data: {
            filePath: url
          }
        },
        res => {}
      );
    },
    /**
     * reject 拒绝
     * approve 批准
     * @param id
     * @param action
     */
    sub(action) {
      if (action == "approve") {
        this.ajaxData(
          {
            type: "post",
            url: `/company/${this.currentCompanyId}/${action}`
          },
          (res, all) => {
            if (all.code == 0) {
              this.getList();
            }
          }
        );
      } else {
        if(this.value1 == ""){
          this.$Notice.error({
            title:"错误",
            desc: "请输入驳回理由"
          });
          return
        }
        this.ajaxData(
          {
            type: "post",
            url: `/company/${this.currentCompanyId}/${action}`,
            data: {
              reason: this.value1
            }
          },
          (res, all) => {
            if (all.code == 0) {
              this.getList();
            }
          }
        );
      }
    },
    cancel() {
      this.$Message.info("拒绝已取消！");
    }
  },
  created() {
    this.urlFormat();
    this.getList();
  }
};
</script>
